using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWARAV
    {
        public DataRow Convert2WARAV(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWARAV(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WARMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WARRAVGRP"] = " ".PadRight(4 ); 
         dwReturn["WARNEUB"] = " ".PadRight(8 ); 
         dwReturn["WARNEUD"] = " ".PadRight(0 ); 
         dwReturn["WARAENB"] = " ".PadRight(8 ); 
         dwReturn["WARAEND"] = " ".PadRight(0 ); 
         dwReturn["WARAENZL"] = " ".PadRight(0 ); 
         dwReturn["WARBEZ"] = " ".PadRight(40 ); 
         dwReturn["WARPARTFIX"] = " ".PadRight(0 ); 
         dwReturn["WARROHSTK"] = " ".PadRight(0 ); 
         dwReturn["WARPROBE"] = " ".PadRight(0 ); 
         dwReturn["WARPROMTR"] = " ".PadRight(0 ); 
         dwReturn["WARPRPROZ"] = " ".PadRight(0 ); 
         dwReturn["WARASVERG"] = " ".PadRight(0 ); 
         dwReturn["WARBISME1"] = " ".PadRight(0 ); 
         dwReturn["WARPROZ1"] = " ".PadRight(0 ); 
         dwReturn["WARBISME2"] = " ".PadRight(0 ); 
         dwReturn["WARPROZ2"] = " ".PadRight(0 ); 
         dwReturn["WARBISME3"] = " ".PadRight(0 ); 
         dwReturn["WARPROZ3"] = " ".PadRight(0 ); 
         dwReturn["WARBISME4"] = " ".PadRight(0 ); 
         dwReturn["WARPROZ4"] = " ".PadRight(0 ); 
         dwReturn["WARBISME5"] = " ".PadRight(0 ); 
         dwReturn["WARPROZ5"] = " ".PadRight(0 ); 
         dwReturn["WARBISME6"] = " ".PadRight(0 ); 
         dwReturn["WARPROZ6"] = " ".PadRight(0 ); 
         dwReturn["WARFILLER"] = " ".PadRight(52 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWARAV(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWARAV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWARAV(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWARAV(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWARAV(dwLocal, ITXDBVERSION);
            }
            UpdateWARAV(dwLocal);
        }
        public void InsertWARAV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WARAV(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWARAV(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WARAV WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WARAV  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WARAV";
            Return = Result;
            return Return;
        }
        public void DeleteWARAV(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WARAV   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWARAV(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WARAV SET "
                    +"WARMANDANT= :WARMANDANT,"
                    +"WARRAVGRP= :WARRAVGRP,"
                    +"WARNEUB= :WARNEUB,"
                    +"WARNEUD= :WARNEUD,"
                    +"WARAENB= :WARAENB,"
                    +"WARAEND= :WARAEND,"
                    +"WARAENZL= :WARAENZL,"
                    +"WARBEZ= :WARBEZ,"
                    +"WARPARTFIX= :WARPARTFIX,"
                    +"WARROHSTK= :WARROHSTK,"
                    +"WARPROBE= :WARPROBE,"
                    +"WARPROMTR= :WARPROMTR,"
                    +"WARPRPROZ= :WARPRPROZ,"
                    +"WARASVERG= :WARASVERG,"
                    +"WARBISME1= :WARBISME1,"
                    +"WARPROZ1= :WARPROZ1,"
                    +"WARBISME2= :WARBISME2,"
                    +"WARPROZ2= :WARPROZ2,"
                    +"WARBISME3= :WARBISME3,"
                    +"WARPROZ3= :WARPROZ3,"
                    +"WARBISME4= :WARBISME4,"
                    +"WARPROZ4= :WARPROZ4,"
                    +"WARBISME5= :WARBISME5,"
                    +"WARPROZ5= :WARPROZ5,"
                    +"WARBISME6= :WARBISME6,"
                    +"WARPROZ6= :WARPROZ6,"
                    +"WARFILLER= :WARFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WARMANDANT", OracleType.NVarChar).Value = dwData["WARMANDANT"].ToString(); 
          or1.Parameters.Add("WARRAVGRP", OracleType.NVarChar).Value = dwData["WARRAVGRP"].ToString(); 
          or1.Parameters.Add("WARNEUB", OracleType.NVarChar).Value = dwData["WARNEUB"].ToString(); 
          or1.Parameters.Add("WARNEUD", OracleType.NVarChar).Value = dwData["WARNEUD"].ToString(); 
          or1.Parameters.Add("WARAENB", OracleType.NVarChar).Value = dwData["WARAENB"].ToString(); 
          or1.Parameters.Add("WARAEND", OracleType.NVarChar).Value = dwData["WARAEND"].ToString(); 
          or1.Parameters.Add("WARAENZL", OracleType.NVarChar).Value = dwData["WARAENZL"].ToString(); 
          or1.Parameters.Add("WARBEZ", OracleType.NVarChar).Value = dwData["WARBEZ"].ToString(); 
          or1.Parameters.Add("WARPARTFIX", OracleType.NVarChar).Value = dwData["WARPARTFIX"].ToString(); 
          or1.Parameters.Add("WARROHSTK", OracleType.NVarChar).Value = dwData["WARROHSTK"].ToString(); 
          or1.Parameters.Add("WARPROBE", OracleType.NVarChar).Value = dwData["WARPROBE"].ToString(); 
          or1.Parameters.Add("WARPROMTR", OracleType.NVarChar).Value = dwData["WARPROMTR"].ToString(); 
          or1.Parameters.Add("WARPRPROZ", OracleType.NVarChar).Value = dwData["WARPRPROZ"].ToString(); 
          or1.Parameters.Add("WARASVERG", OracleType.NVarChar).Value = dwData["WARASVERG"].ToString(); 
          or1.Parameters.Add("WARBISME1", OracleType.NVarChar).Value = dwData["WARBISME1"].ToString(); 
          or1.Parameters.Add("WARPROZ1", OracleType.NVarChar).Value = dwData["WARPROZ1"].ToString(); 
          or1.Parameters.Add("WARBISME2", OracleType.NVarChar).Value = dwData["WARBISME2"].ToString(); 
          or1.Parameters.Add("WARPROZ2", OracleType.NVarChar).Value = dwData["WARPROZ2"].ToString(); 
          or1.Parameters.Add("WARBISME3", OracleType.NVarChar).Value = dwData["WARBISME3"].ToString(); 
          or1.Parameters.Add("WARPROZ3", OracleType.NVarChar).Value = dwData["WARPROZ3"].ToString(); 
          or1.Parameters.Add("WARBISME4", OracleType.NVarChar).Value = dwData["WARBISME4"].ToString(); 
          or1.Parameters.Add("WARPROZ4", OracleType.NVarChar).Value = dwData["WARPROZ4"].ToString(); 
          or1.Parameters.Add("WARBISME5", OracleType.NVarChar).Value = dwData["WARBISME5"].ToString(); 
          or1.Parameters.Add("WARPROZ5", OracleType.NVarChar).Value = dwData["WARPROZ5"].ToString(); 
          or1.Parameters.Add("WARBISME6", OracleType.NVarChar).Value = dwData["WARBISME6"].ToString(); 
          or1.Parameters.Add("WARPROZ6", OracleType.NVarChar).Value = dwData["WARPROZ6"].ToString(); 
          or1.Parameters.Add("WARFILLER", OracleType.NVarChar).Value = dwData["WARFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
